package util;

import common.ApplicationVariable;
import model.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @description: 得到登录的用户
 * @author: chengbaiyi
 * @create: 2022-06-26 13:19
 */
public class SessionUtil {
    public static UserInfo getSessionUserInfo(HttpServletRequest req) {
        HttpSession session = req.getSession(false);
        UserInfo userInfo = null;
        if (session != null && session.getAttribute(ApplicationVariable.SESSION_USER_KEY) != null) {
            userInfo = (UserInfo) session.getAttribute(ApplicationVariable.SESSION_USER_KEY);
        }
        return userInfo;
    }
}
